/**
	@file test.c
	@author Andrew D. Zonenberg
	@brief C-language test program
 */
#include <achd-soc.h>

const char* str __attribute__ ((section(".rodata"))) = "Hello from C!\r\n";

void print(const char* str) __attribute__ ((section(".startup")));

void main(void)
{
	//80 MHz / 115200 baud
	U1BRG = 695;
	
	//Turn on the LEDs
	LEDBANKA = 0x55;
	
	//Print the string
	print(str);	
	
	while(1);
}

void print(const char* str)
{
	while(*str)
	{
		//if buffer is full, busy-wait till it's empty
		if(U1STATbits.TXFULL)
		{
			while(!U1STATbits.TXEMPTY)
			{}
		}
		
		//Send the byte
		U1TXBUF = *str;
	
		str++;
	}
}
